// pages/shortMsgDetail/shortMsgDetail.js
import * as API from '../../../api/msgApi';
import * as util from '../../../utils/util';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    tapStatus: true,
    id: '',
    orderParams: {
      dataSource: [],
      pageNo: 1,
      pageSize: 10,
      total: 0,
      hasMore: false,
      hasRequest: false,
      networkError: false,
      total: 0
    },

  },

  /**
   * 打开目标页面
   */
  goto: function (e) {
    util.preventMoreClick(this, () => {
      let status = e.currentTarget.dataset.status > 0;
      this.setData({
        tapStatus: !!status
      })
      this.setData({
        pageNo: 1,
        pageSize: 10,
        total: 0,
      })
      // if (url && url.length) {
      //   wx.navigateTo({
      //     url: url
      //   });
      // }
    })
  },
  getCustomerInfo: function () {
    API.getShortMsgDetail(this.data.id).then(data => {
      let msg = data.shortMessage;
      console.log(msg)
      console.log(msg.customId)
      this.setData({
        customId: msg.customId,
        customName: msg.customName,
        amount: msg.amount,
        successCount: msg.successCount,
        failCount: msg.failCount,
        deliveryDate: msg.deliveryDate,
        createDate: msg.createDate,
        deliveryOrderNum: msg.deliveryOrderNum,
        phoneNums: msg.phoneNums
      });
    }, err => {
      wx.showToast({
        title: err,
        icon: 'none'
      });
    })
  },
  // getOrderListParams: function () {
  //   API.getOrderList(this.data.id, this.data.orderParams.pageNo, this.data.orderParams.pageSize).then(data => {
  //     let arr = data.orderList || [];
  //     // if (!options) {
  //     //   arr = this.data.dataSource.concat(data.orderList || []);
  //     // }
  //     console.log(arr)
  //     let params = {
  //       orderParams: {
  //         dataSource: arr,
  //         hasMore: hasMore,
  //         hasRequest: true,
  //         networkError: false,
  //         total: data.totalCount
  //       }
  //     }
  //     let hasMore = arr.length < data.totalCount;
  //     this.setData({
  //       data: params
  //     });
  //   }, err => {
  //     this.setData({
  //       networkError: true
  //     });
  //   })
  // },
  getPhoneList: function () {},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let id = options.id || 'id';
    this.setData({
      id: id
    });

  },

  onShow: function () {
    this.getCustomerInfo();
    // this.getOrderListParams();
  },
  onPullDownRefresh: function () {
    console.log('加载')
    // 重新加载
    // this.clear();
    // this.loadData(false);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    // 增量加载
    console.log('ok')
    this.setData({
      reachTime: new Date().getTime()
    })
    // var hasMore = this.data.dataSource.length < this.data.total;
    // if (hasMore) {
    //   this.setData({
    //     pageNo: ++this.data.pageNo
    //   });
    //   this.loadData(false);
    // }
  }
})